/**
 * 电表类
 */
import {meterMeterDataCollection} from "@/api/source.js";
import  * as math from 'mathjs';

export class ElectricMeter {
    /**
     * 电表类型
     * @type {string}
     */
    type;

    /**
     * 电表名称
     * @type {string}
     */
    name;

    /**
     * 表位
     * @type {string}
     */
    location;

    /**
     * 电表型号
     * @type {string}
     */
    model;

    /**
     * 接线方式
     * @type {string}
     */
    wiringMethod;

    /**
     * 电压
     * @type {number}
     */
    voltage;

    /**
     * 电流
     * @type {number}
     */
    current;

    /**
     * 通讯地址
     * @type {string}
     */
    communicationAddress;

    /**
     * PT
     * @type {number}
     */
    pt;

    /**
     * CT
     * @type {number}
     */
    ct;

    /**
     * 安装地址
     * @type {string}
     */
    installationAddress;

    /**
     * 当前正向有功总电能
     * @type {number}
     */
    currentForwardActiveEnergy;

    /**
     * 当前正向尖电能
     * @type {number}
     */
    currentForwardPeakEnergy;

    /**
     * 当前正向峰电能
     * @type {number}
     */
    currentForwardValleyEnergy;

    /**
     * 当前正向平电能
     * @type {number}
     */
    currentForwardLevelEnergy;

    /**
     * 当前正向谷电能
     * @type {number}
     */
    currentForwardTroughEnergy;

    /**
     * 当前反向有功总电能
     * @type {number}
     */
    currentReverseActiveEnergy;

    /**
     * 当前反向尖电能
     * @type {number}
     */
    currentReversePeakEnergy;

    /**
     * 当前反向峰电能
     * @type {number}
     */
    currentReverseValleyEnergy;

    /**
     * 当前反向平电能
     * @type {number}
     */
    currentReverseLevelEnergy;

    /**
     * 当前反向谷电能
     * @type {number}
     */
    currentReverseTroughEnergy;

    /**
     * 上月正向有功总电能
     * @type {number}
     */
    lastMonthForwardActiveEnergy;

    /**
     * 上月正向尖电能
     * @type {number}
     */
    lastMonthForwardPeakEnergy;

    /**
     * 上月正向峰电能
     * @type {number}
     */
    lastMonthForwardValleyEnergy;

    /**
     * 上月正向平电能
     * @type {number}
     */
    lastMonthForwardLevelEnergy;

    /**
     * 上月正向谷电能
     * @type {number}
     */
    lastMonthForwardTroughEnergy;

    /**
     * 上月反向有功总电能
     * @type {number}
     */
    lastMonthReverseActiveEnergy;

    /**
     * 上月反向尖电能
     * @type {number}
     */
    lastMonthReversePeakEnergy;

    /**
     * 上月反向峰电能
     * @type {number}
     */
    lastMonthReverseValleyEnergy;

    /**
     * 上月反向平电能
     * @type {number}
     */
    lastMonthReverseLevelEnergy;

    /**
     * 上月反向谷电能
     * @type {number}
     */
    lastMonthReverseTroughEnergy;

    /**
     * 变比
     * @type {number}
     */
    ratio;

    /**
     * 瞬时功率
     * @type {number}
     */
    instantaneousPower;

    /**
     * 用户表电源额定功率与当前功率的比值
     * @type {number}
     */
    powerRatio;


    /**
     * 电压相序
     */
    uPhaseSequence
    /**
     * 电刘相序
     */
    iPhaseSequence


    constructor(
        type,
        name,
        location,
        model,
        wiringMethod,
        voltage,
        current,
        communicationAddress,
        pt,
        ct,
        installationAddress,
        currentForwardActiveEnergy,
        currentForwardPeakEnergy,
        currentForwardValleyEnergy,
        currentForwardLevelEnergy,
        currentForwardTroughEnergy,
        currentForwardDeepTroughEnergy,
        currentReverseActiveEnergy,
        currentReversePeakEnergy,
        currentReverseValleyEnergy,
        currentReverseLevelEnergy,
        currentReverseTroughEnergy,
        lastMonthForwardActiveEnergy,
        lastMonthForwardPeakEnergy,
        lastMonthForwardValleyEnergy,
        lastMonthForwardLevelEnergy,
        lastMonthForwardTroughEnergy,
        lastMonthForwardDeepTroughEnergy,
        lastMonthReverseActiveEnergy,
        lastMonthReversePeakEnergy,
        lastMonthReverseValleyEnergy,
        lastMonthReverseLevelEnergy,
        lastMonthReverseTroughEnergy,
        ratio,
        instantaneousPower,
        powerRatio,
        planId,
        uPhaseSequence,
        iPhaseSequence,
    ) {
        this.type = type === '失败' ? 0 : type
        this.name = name === '失败' ? 0 : name
        this.location = location === '失败' ? 0 : location
        this.model = model === '失败' ? 0 : model
        this.wiringMethod = wiringMethod === '失败' ? 0 : wiringMethod
        this.voltage = voltage === '失败' ? 0 : voltage
        this.current = current === '失败' ? 0 : current
        this.communicationAddress = communicationAddress === '失败' ? 0 : communicationAddress
        this.pt = pt === '失败' ? 0 : pt
        this.ct = ct === '失败' ? 0 : ct
        this.installationAddress = installationAddress === '失败' ? 0 : installationAddress
        this.currentForwardActiveEnergy = currentForwardActiveEnergy === '失败' ? 0 : currentForwardActiveEnergy
        this.currentForwardPeakEnergy = currentForwardPeakEnergy === '失败' ? 0 : currentForwardPeakEnergy
        this.currentForwardValleyEnergy = currentForwardValleyEnergy === '失败' ? 0 : currentForwardValleyEnergy
        this.currentForwardLevelEnergy = currentForwardLevelEnergy === '失败' ? 0 : currentForwardLevelEnergy
        this.currentForwardTroughEnergy = currentForwardTroughEnergy === '失败' ? 0 : currentForwardTroughEnergy
        this.currentForwardDeepTroughEnergy = currentForwardTroughEnergy === '失败' ? 0 : currentForwardDeepTroughEnergy
        this.currentReverseActiveEnergy = currentReverseActiveEnergy === '失败' ? 0 : currentReverseActiveEnergy
        this.currentReversePeakEnergy = currentReversePeakEnergy === '失败' ? 0 : currentReversePeakEnergy
        this.currentReverseValleyEnergy = currentReverseValleyEnergy === '失败' ? 0 : currentReverseValleyEnergy
        this.currentReverseLevelEnergy = currentReverseLevelEnergy === '失败' ? 0 : currentReverseLevelEnergy
        this.currentReverseTroughEnergy = currentReverseTroughEnergy === '失败' ? 0 : currentReverseTroughEnergy
        this.lastMonthForwardActiveEnergy = lastMonthForwardActiveEnergy === '失败' ? 0 : lastMonthForwardActiveEnergy
        this.lastMonthForwardPeakEnergy = lastMonthForwardPeakEnergy === '失败' ? 0 : lastMonthForwardPeakEnergy
        this.lastMonthForwardValleyEnergy = lastMonthForwardValleyEnergy === '失败' ? 0 : lastMonthForwardValleyEnergy
        this.lastMonthForwardLevelEnergy = lastMonthForwardLevelEnergy === '失败' ? 0 : lastMonthForwardLevelEnergy
        this.lastMonthForwardTroughEnergy = lastMonthForwardTroughEnergy === '失败' ? 0 : lastMonthForwardTroughEnergy
        this.lastMonthForwardDeepTroughEnergy = lastMonthForwardTroughEnergy === '失败' ? 0 : lastMonthForwardDeepTroughEnergy
        this.lastMonthReverseActiveEnergy = lastMonthReverseActiveEnergy === '失败' ? 0 : lastMonthReverseActiveEnergy
        this.lastMonthReversePeakEnergy = lastMonthReversePeakEnergy === '失败' ? 0 : lastMonthReversePeakEnergy
        this.lastMonthReverseValleyEnergy = lastMonthReverseValleyEnergy === '失败' ? 0 : lastMonthReverseValleyEnergy
        this.lastMonthReverseLevelEnergy = lastMonthReverseLevelEnergy === '失败' ? 0 : lastMonthReverseLevelEnergy
        this.lastMonthReverseTroughEnergy = lastMonthReverseTroughEnergy === '失败' ? 0 : lastMonthReverseTroughEnergy
        this.ratio = ratio === '失败' ? 0 : ratio
        this.instantaneousPower = instantaneousPower === '失败' ? 0 : instantaneousPower
        this.powerRatio = powerRatio === '失败' ? 0 : powerRatio
        this.planId = planId === '失败' ? 0 : planId
        this.uPhaseSequence = uPhaseSequence === '失败' ? 0 : uPhaseSequence
        this.iPhaseSequence = iPhaseSequence === '失败' ? 0 : iPhaseSequence

    }
}


export class LineLose {

    /**
     * 电能表
     * @type{List<ElectricMeter>}
     */
    meter

    /**
     * 电源功率
     */
    power


    currentForwardActiveEnergySum
    currentForwardPeakEnergySum
    currentForwardValleyEnergySum
    currentForwardLevelEnergySum
    currentForwardTroughEnergySum
    currentReverseActiveEnergySum
    currentReversePeakEnergySum
    currentReverseValleyEnergySum
    currentReverseLevelEnergySum
    currentReverseTroughEnergySum
    lastMonthForwardActiveEnergySum
    lastMonthForwardPeakEnergySum
    lastMonthForwardValleyEnergySum
    lastMonthForwardLevelEnergySum
    lastMonthForwardTroughEnergySum
    lastMonthReverseActiveEnergySum
    lastMonthReversePeakEnergySum
    lastMonthReverseValleyEnergySum
    lastMonthReverseLevelEnergySum
    lastMonthReverseTroughEnergySum
    powerRatioSum

    /**
     * 总表
     */
    fstMeter

    /**
     * 总表功率比值
     */
    totalMeterPower

    /**
     * 更正系数
     */
    g = 1

    constructor(meter, power) {
        console.log('1meter', meter)
        /**
         * 将meter第一项之后的赋值给this.meter
         */

        this.fstMeter = meter[0];
        this.meter = meter.slice(1);
        // this.power = power;
        if(power){
            let phase = JSON.parse(power.phase)
            let source = JSON.parse(power.source).state
            phase['pua'] = 0
            let pp = ['a', 'b', 'c']
            this.power = {}
            let powerTotal = 0
            for (const p of pp) {
                this.power['power' + p.toUpperCase()] = source['u' + p] * source['i' + p]
                this.power['cos' + p.toUpperCase()] = Math.cos((phase['pi' + p] - phase['pu' + p]) * Math.PI / 180)
                powerTotal += (this.power['power' + p.toUpperCase()] * this.power['cos' + p.toUpperCase()])
            }
            this.power.powerTotal = powerTotal
        }

        console.log(this.power)
        console.log(this.meter)
    }

    /**
     * 计算线损
     */
    async calculate() {
        let xs = await this.calculateByFormula()
        return xs
    }


    /**
     * 第三步,乘变比
     */
    multiplyRatio() {
        for (const meter of this.meter) {

            meter.currentForwardActiveEnergyRatio = meter.currentForwardActiveEnergy * (meter.pt / meter.ct)
            meter.currentForwardPeakEnergyRatio = meter.currentForwardPeakEnergy * (meter.pt / meter.ct)
            meter.currentForwardValleyEnergyRatio = meter.currentForwardValleyEnergy * (meter.pt / meter.ct)
            meter.currentForwardLevelEnergyRatio = meter.currentForwardLevelEnergy * (meter.pt / meter.ct)
            meter.currentForwardTroughEnergyRatio = meter.currentForwardTroughEnergy * (meter.pt / meter.ct)
            meter.currentReverseActiveEnergyRatio = meter.currentReverseActiveEnergy * (meter.pt / meter.ct)
            meter.currentReversePeakEnergyRatio = meter.currentReversePeakEnergy * (meter.pt / meter.ct)
            meter.currentReverseValleyEnergyRatio = meter.currentReverseValleyEnergy * (meter.pt / meter.ct)
            meter.currentReverseLevelEnergyRatio = meter.currentReverseLevelEnergy * (meter.pt / meter.ct)
            meter.currentReverseTroughEnergyRatio = meter.currentReverseTroughEnergy * (meter.pt / meter.ct)
            meter.lastMonthForwardActiveEnergyRatio = meter.lastMonthForwardActiveEnergy * (meter.pt / meter.ct)
            meter.lastMonthForwardPeakEnergyRatio = meter.lastMonthForwardPeakEnergy * (meter.pt / meter.ct)
            meter.lastMonthForwardValleyEnergyRatio = meter.lastMonthForwardValleyEnergy * (meter.pt / meter.ct)
            meter.lastMonthForwardLevelEnergyRatio = meter.lastMonthForwardLevelEnergy * (meter.pt / meter.ct)
            meter.lastMonthForwardTroughEnergyRatio = meter.lastMonthForwardTroughEnergy * (meter.pt / meter.ct)
            meter.lastMonthReverseActiveEnergyRatio = meter.lastMonthReverseActiveEnergy * (meter.pt / meter.ct)
            meter.lastMonthReversePeakEnergyRatio = meter.lastMonthReversePeakEnergy * (meter.pt / meter.ct)
            meter.lastMonthReverseValleyEnergyRatio = meter.lastMonthReverseValleyEnergy * (meter.pt / meter.ct)
            meter.lastMonthReverseLevelEnergyRatio = meter.lastMonthReverseLevelEnergy * (meter.pt / meter.ct)
            meter.lastMonthReverseTroughEnergyRatio = meter.lastMonthReverseTroughEnergy * (meter.pt / meter.ct)
        }
    }

    /**
     * 第五步，计算电源额定功率和当前功率比值
     */
    calculatePowerRatio() {
        for (const meter of this.meter) {
            meter.powerRatio = this.power / meter.instantaneousPower
        }
    }

    /**
     * 第六步，计算第五步和第三步的积
     */
    calculatePowerRatioAndEnergy() {
        for (const meter of this.meter) {
            meter.currentForwardActiveEnergyProduct = meter.currentForwardActiveEnergyRatio * meter.powerRatio
            meter.currentForwardPeakEnergyProduct = meter.currentForwardPeakEnergyRatio * meter.powerRatio
            meter.currentForwardValleyEnergyProduct = meter.currentForwardValleyEnergyRatio * meter.powerRatio
            meter.currentForwardLevelEnergyProduct = meter.currentForwardLevelEnergyRatio * meter.powerRatio
            meter.currentForwardTroughEnergyProduct = meter.currentForwardTroughEnergyRatio * meter.powerRatio
            meter.currentReverseActiveEnergyProduct = meter.currentReverseActiveEnergyRatio * meter.powerRatio
            meter.currentReversePeakEnergyProduct = meter.currentReversePeakEnergyRatio * meter.powerRatio
            meter.currentReverseValleyEnergyProduct = meter.currentReverseValleyEnergyRatio * meter.powerRatio
            meter.currentReverseLevelEnergyProduct = meter.currentReverseLevelEnergyRatio * meter.powerRatio
            meter.currentReverseTroughEnergyProduct = meter.currentReverseTroughEnergyRatio * meter.powerRatio
            meter.lastMonthForwardActiveEnergyProduct = meter.lastMonthForwardActiveEnergyRatio * meter.powerRatio
            meter.lastMonthForwardPeakEnergyProduct = meter.lastMonthForwardPeakEnergyRatio * meter.powerRatio
            meter.lastMonthForwardValleyEnergyProduct = meter.lastMonthForwardValleyEnergyRatio * meter.powerRatio
            meter.lastMonthForwardLevelEnergyProduct = meter.lastMonthForwardLevelEnergyRatio * meter.powerRatio
            meter.lastMonthForwardTroughEnergyProduct = meter.lastMonthForwardTroughEnergyRatio * meter.powerRatio
            meter.lastMonthReverseActiveEnergyProduct = meter.lastMonthReverseActiveEnergyRatio * meter.powerRatio
            meter.lastMonthReversePeakEnergyProduct = meter.lastMonthReversePeakEnergyRatio * meter.powerRatio
            meter.lastMonthReverseValleyEnergyProduct = meter.lastMonthReverseValleyEnergyRatio * meter.powerRatio
            meter.lastMonthReverseLevelEnergyProduct = meter.lastMonthReverseLevelEnergyRatio * meter.powerRatio
            meter.lastMonthReverseTroughEnergyProduct = meter.lastMonthReverseTroughEnergyRatio * meter.powerRatio
        }
    }


    /**
     * 第七步，计算用户值(第六项)之和
     */
    calculateMeterValuesSum() {
        for (const meter of this.meter) {
            this.currentForwardActiveEnergySum += meter.currentForwardActiveEnergyProduc
            this.currentForwardPeakEnergySum += meter.currentForwardPeakEnergyProduc
            this.currentForwardValleyEnergySum += meter.currentForwardValleyEnergyProduc
            this.currentForwardLevelEnergySum += meter.currentForwardLevelEnergyProduc
            this.currentForwardTroughEnergySum += meter.currentForwardTroughEnergyProduc
            this.currentReverseActiveEnergySum += meter.currentReverseActiveEnergyProduc
            this.currentReversePeakEnergySum += meter.currentReversePeakEnergyProduc
            this.currentReverseValleyEnergySum += meter.currentReverseValleyEnergyProduc
            this.currentReverseLevelEnergySum += meter.currentReverseLevelEnergyProduc
            this.currentReverseTroughEnergySum += meter.currentReverseTroughEnergyProduc
            this.lastMonthForwardActiveEnergySum += meter.lastMonthForwardActiveEnergyProduc
            this.lastMonthForwardPeakEnergySum += meter.lastMonthForwardPeakEnergyProduc
            this.lastMonthForwardValleyEnergySum += meter.lastMonthForwardValleyEnergyProduc
            this.lastMonthForwardLevelEnergySum += meter.lastMonthForwardLevelEnergyProduc
            this.lastMonthForwardTroughEnergySum += meter.lastMonthForwardTroughEnergyProduc
            this.lastMonthReverseActiveEnergySum += meter.lastMonthReverseActiveEnergyProduc
            this.lastMonthReversePeakEnergySum += meter.lastMonthReversePeakEnergyProduc
            this.lastMonthReverseValleyEnergySum += meter.lastMonthReverseValleyEnergyProduc
            this.lastMonthReverseLevelEnergySum += meter.lastMonthReverseLevelEnergyProduc
            this.lastMonthReverseTroughEnergySum += meter.lastMonthReverseTroughEnergyProduc
        }
    }

    /**
     * 第九步，总表当前功率与电源额定功率的比值
     */
    calculatePower() {
        this.totalMeterPower = this.fstMeter.instantaneousPower / this.power.powerTotal
    }


    // /**
    //  * 计算线损
    //  */
    // calculate() {
    //     for (const meter of this.meter) {
    //         // 计算第六项，第三项 * 第五项
    //         // 电能分别各自乘以对应用户设置的	PT/CT变比  乘  功率比值，为每一个用户表电源额定功率与当前功率的比
    //         meter.currentForwardActiveEnergy *= (meter.pt / meter.bt) * (this.power / meter.instantaneousPower)
    //         meter.currentForwardPeakEnergy *= (meter.pt / meter.bt) * (this.power / meter.instantaneousPower)
    //         meter.currentForwardValleyEnergy *= (meter.pt / meter.bt) * (this.power / meter.instantaneousPower)
    //         meter.currentForwardLevelEnergy *= (meter.pt / meter.bt) * (this.power / meter.instantaneousPower)
    //         meter.currentForwardTroughEnergy *= (meter.pt / meter.bt) * (this.power / meter.instantaneousPower)
    //         meter.currentReverseActiveEnergy *= (meter.pt / meter.bt) * (this.power / meter.instantaneousPower)
    //         meter.currentReversePeakEnergy *= (meter.pt / meter.bt) * (this.power / meter.instantaneousPower)
    //         meter.currentReverseValleyEnergy *= (meter.pt / meter.bt) * (this.power / meter.instantaneousPower)
    //         meter.currentReverseLevelEnergy *= (meter.pt / meter.bt) * (this.power / meter.instantaneousPower)
    //         meter.currentReverseTroughEnergy *= (meter.pt / meter.bt) * (this.power / meter.instantaneousPower)
    //         meter.lastMonthForwardActiveEnergy *= (meter.pt / meter.bt) * (this.power / meter.instantaneousPower)
    //         meter.lastMonthForwardPeakEnergy *= (meter.pt / meter.bt) * (this.power / meter.instantaneousPower)
    //         meter.lastMonthForwardValleyEnergy *= (meter.pt / meter.bt) * (this.power / meter.instantaneousPower)
    //         meter.lastMonthForwardLevelEnergy *= (meter.pt / meter.bt) * (this.power / meter.instantaneousPower)
    //         meter.lastMonthForwardTroughEnergy *= (meter.pt / meter.bt) * (this.power / meter.instantaneousPower)
    //         meter.lastMonthReverseActiveEnergy *= (meter.pt / meter.bt) * (this.power / meter.instantaneousPower)
    //         meter.lastMonthReversePeakEnergy *= (meter.pt / meter.bt) * (this.power / meter.instantaneousPower)
    //         meter.lastMonthReverseValleyEnergy *= (meter.pt / meter.bt) * (this.power / meter.instantaneousPower)
    //         meter.lastMonthReverseLevelEnergy *= (meter.pt / meter.bt) * (this.power / meter.instantaneousPower)
    //         meter.lastMonthReverseTroughEnergy *= (meter.pt / meter.bt) * (this.power / meter.instantaneousPower)
    //
    //
    //     }
    //
    //
    //     // 计算第七项
    //     //
    //     for (const meter of this.meter) {
    //         this.currentForwardActiveEnergySum += meter.currentForwardActiveEnergy
    //         this.currentForwardPeakEnergySum += meter.currentForwardPeakEnergy
    //         this.currentForwardValleyEnergySum += meter.currentForwardValleyEnergy
    //         this.currentForwardLevelEnergySum += meter.currentForwardLevelEnergy
    //         this.currentForwardTroughEnergySum += meter.currentForwardTroughEnergy
    //         this.currentReverseActiveEnergySum += meter.currentReverseActiveEnergy
    //         this.currentReversePeakEnergySum += meter.currentReversePeakEnergy
    //         this.currentReverseValleyEnergySum += meter.currentReverseValleyEnergy
    //         this.currentReverseLevelEnergySum += meter.currentReverseLevelEnergy
    //         this.currentReverseTroughEnergySum += meter.currentReverseTroughEnergy
    //         this.lastMonthForwardActiveEnergySum += meter.lastMonthForwardActiveEnergy
    //         this.lastMonthForwardPeakEnergySum += meter.lastMonthForwardPeakEnergy
    //         this.lastMonthForwardValleyEnergySum += meter.lastMonthForwardValleyEnergy
    //         this.lastMonthForwardLevelEnergySum += meter.lastMonthForwardLevelEnergy
    //         this.lastMonthForwardTroughEnergySum += meter.lastMonthForwardTroughEnergy
    //         this.lastMonthReverseActiveEnergySum += meter.lastMonthReverseActiveEnergy
    //         this.lastMonthReversePeakEnergySum += meter.lastMonthReversePeakEnergy
    //         this.lastMonthReverseValleyEnergySum += meter.lastMonthReverseValleyEnergy
    //         this.lastMonthReverseLevelEnergySum += meter.lastMonthReverseLevelEnergy
    //         this.lastMonthReverseTroughEnergySum += meter.lastMonthReverseTroughEnergy
    //
    //
    //     }
    //
    //
    //     // 第九项，计算：总表当前功率与电源额定功率的比值
    //     this.totalMeterPower = this.fstMeter.currentForwardActiveEnergy / this.power
    //
    //
    // }

    /**
     * 用公式计算
     */
    async calculateByFormula() {
        // 计算用户表剑锋评估电能
        let syTotal1 = 0
        let syTotal2 = 0
        let syTotal3 = 0
        let syTotal4 = 0
        let syTotal5 = 0

        // 当月正向尖电量
        let enSum1 = 0
        for (let i = 0; i < this.meter.length; i++) {
            let m = this.meter[i]
            enSum1 += (m.currentForwardPeakEnergy - m.lastMonthForwardPeakEnergy)
            let ptStr = m.pt
            let pt = m.wiringMethod === '单相' ? 1 : math.evaluate(ptStr)
            let ct = math.evaluate(m.ct)
            m.pt = typeof pt === "number" ? pt : pt.value
            m.ct = typeof ct === "number" ? ct : ct.value
            let power = m.wiringMethod === '单相' ? this.power['power' + m.installationAddress] * this.power['cos' + m.installationAddress] : this.power.powerTotal
            syTotal1 += (m.currentForwardPeakEnergy - m.lastMonthForwardPeakEnergy) * m.pt * m.ct * m.instantaneousPower / power
            syTotal2 += (m.currentForwardValleyEnergy - m.lastMonthForwardValleyEnergy) * m.pt * m.ct * m.instantaneousPower / power
            syTotal3 += (m.currentForwardLevelEnergy - m.lastMonthForwardLevelEnergy) * m.pt * m.ct * m.instantaneousPower / power
            syTotal4 += (m.currentForwardTroughEnergy - m.lastMonthForwardTroughEnergy) * m.pt * m.ct * m.instantaneousPower / power
            syTotal5 += (m.currentForwardDeepTroughEnergy - m.lastMonthForwardDeepTroughEnergy) * m.pt * m.ct * m.instantaneousPower / power

        }
        let pt = math.evaluate(this.fstMeter.pt.replace(/[kV]/, ''))
        let ct = math.evaluate(this.fstMeter.ct.replace('A', ''))
        this.fstMeter.pt = typeof pt === "number" ? pt : pt.value
        this.fstMeter.ct =  typeof ct === "number" ? ct : ct.value
        let sftPowerRate = this.fstMeter.pt * this.fstMeter.ct * this.fstMeter.instantaneousPower / this.power.powerTotal
        let sftTotal1 = sftPowerRate ? (syTotal1 / sftPowerRate) : 0
        let sftTotal2 = sftPowerRate ? (syTotal2 / sftPowerRate) : 0
        let sftTotal3 = sftPowerRate ? (syTotal3 / sftPowerRate) : 0
        let sftTotal4 = sftPowerRate ? (syTotal4 / sftPowerRate) : 0
        let sftTotal5 = sftPowerRate ? (syTotal5 / sftPowerRate) : 0
        let sftTotal = [sftTotal1.toFixed(2), sftTotal2.toFixed(2), sftTotal3.toFixed(2), sftTotal4.toFixed(2), sftTotal5.toFixed(2)]

        // 计算线损率
        let loseLine = (enSum1 === 0 ? 100 :  ((1 - sftTotal1 / enSum1 ) * 100).toFixed(2)) + '%'
        console.log(1111, sftTotal1, enSum1)

        let methodNames = ['lastMonthForwardPeakEnergy', 'lastMonthForwardValleyEnergy', 'lastMonthForwardLevelEnergy', 'lastMonthForwardTroughEnergy', 'lastMonthForwardDeepTroughEnergy']


        for (let i = 1; i < 6; i++) {
            try {
                // 真是电量
                let realPower = Number(this.fstMeter[methodNames[i - 1]]) + Number(sftTotal[i - 1])
                console.log(realPower)
                let parm2 = {
                    pos: this.fstMeter.location,
                    planId: this.fstMeter.planId,
                    methodName: 'writePositiveActiveEnergy',
                    parm: [
                        i,
                        0,
                        realPower
                    ]
                }
                await meterMeterDataCollection(parm2).then(res => {
                console.log(res)
                }).catch()
            } catch (e) {
                console.log(e)
            }
        }


        // let sz = syTotal * this.fstMeter.instantaneousPower * this.g / (this.fstMeter.pt * this.fstMeter.ct * this.power)
        return loseLine

    }


}
